from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet

from apps.goods.models import SPUSpecification, SPU, SpecificationOption
from apps.meiduo_admin.serializers.options import OptionsSerializers
from apps.meiduo_admin.serializers.specs import SpecsSerializers, SPUserializers
from apps.meiduo_admin.utils import PageNum


class OptionsView(ModelViewSet):
    # 指定序列化器
    serializer_class = OptionsSerializers
    # 指定查询集
    queryset = SpecificationOption.objects.all()

    # 指定分页器
    pagination_class = PageNum

    # 获取规格
    def simple(self,request):
        # 1.查询规格表获取规格信息
        spu = SPUSpecification.objects.all()
        # 2.序列化返回规格信息
        ser = SpecsSerializers(spu,many=True)
        return Response(ser.data)